package com.ssi.mrms.action.room;

import static com.opensymphony.xwork2.Action.SUCCESS;

import java.util.LinkedHashMap;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;

import com.ssi.mrms.action.BaseAction;
import com.ssi.mrms.model.DataTableModel;
import com.ssi.mrms.model.JQueryDataTableParamModel;
import com.ssi.mrms.model.RMactwModel;
import com.ssi.mrms.service.KeyCardServiec;
import com.ssi.mrms.utils.DataTablesParamUtility;

@Namespaces(value = { @Namespace("/room") })
@ParentPackage(value = "json-default")
public class RM006JsonAction extends BaseAction {

	private static final Logger logger = Logger.getLogger(RM006JsonAction.class);
	private LinkedHashMap<String, Object> jsonData = new LinkedHashMap<>();
	
	private JQueryDataTableParamModel<RMactwModel> tableUserModel = null;
	private KeyCardServiec keyCardServiec = lookupBean(KeyCardServiec.class, "keyCardServiec");
	private RMactwModel model;

	public String execute() throws Exception {
		logger.info( getClass());
		return SUCCESS;
	}

	@Action(value = "getDataTableRM006", results = { @Result(name = SUCCESS, type = "json", params = { "root", "jsonData" }) })
	public String getData() throws Exception {
		logger.info("#@@@@@@@@@#getDataTableRM006");
		jsonData.clear();
		tableUserModel = DataTablesParamUtility.getParam(getRequest());
		
		DataTableModel<RMactwModel> dataTableModel = keyCardServiec.getUsersDataTable(
				model, 
				tableUserModel.iDisplayStart,
				tableUserModel.iDisplayLength
			);
		
		if (null != dataTableModel) {
			jsonData.putAll(tableUserModel.toJSON(dataTableModel));
		}
		
		
		return SUCCESS;
	}

	@JSON(name = "jsonData")
	public LinkedHashMap<String, Object> getJsonData() {
		return jsonData;
	}


	@JSON(name = "tableUserModel")
	public JQueryDataTableParamModel<RMactwModel> getTableUserModel() {
		return tableUserModel;
	}

	public RMactwModel getModel() {
		return model;
	}


	public void setTableUserModel(
			JQueryDataTableParamModel<RMactwModel> tableUserModel) {
		this.tableUserModel = tableUserModel;
	}

	public void setModel(RMactwModel model) {
		this.model = model;
	}

	

}
